package com.passioneffect.utils {
	import flash.display.Stage;
	import flash.events.Event;			

	/**
	 * @author Passion Effect
	 */
	public class DoLater {
		static private var funcs:Array;
		static private var stage:Stage;
		
		static public function push(stage:Stage,tfunc:Function):void{
			if(funcs==null)funcs=[];
			
			for each(var func:Function in funcs){
				if(func==tfunc)return;
			}
			
			funcs.push(tfunc);
			DoLater.stage=stage;
			DoLater.stage.addEventListener(Event.ENTER_FRAME,doFuncs);
		}
		
		static private function doFuncs(event : Event) : void {
			DoLater.stage.removeEventListener(Event.ENTER_FRAME,doFuncs);
			for each(var func:Function in funcs){
				func();
			}
			funcs=[];
		}
	}
}
